package panda.server.util;

import java.io.File;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import panda.client.enumerations.MagicSet;
import panda.server.data.CardData;
import panda.server.data.MagicCardDB;




/**
 * Sandbox for testing random shit =)
 * 
 * @author zane.tian@gmail.com
 */
public class Sandbox {
	final static long appStartTime = System.currentTimeMillis();

	public static void main(String[] args) throws Exception {
		System.out.println("Loading at " + (System.currentTimeMillis() - appStartTime) + "ms\n-\n");
		
		List<CardData> cards = MagicCardDB.getCardsFromSet(MagicSet.M_11);
		for(CardData data : cards) {
			System.out.println("1 " + data.getName());
		}
		
		System.out.println("\n-\nDone in: " + (System.currentTimeMillis() - appStartTime) + "ms");
	}
	
	/**
	 * Some test code for scraping magiccards.info price data from http://magiccards.info/$setAbbrev/en/$id.html
	 */
	public static void mciPriceMatch() { 
		StringBuffer pageContents = new StringBuffer();
		
		try {
			/* new File("/zen-page-src.txt") */
			Scanner scanner = new Scanner(new File("src/panda/cardutil/other/zen-page-src.txt")); 
			while (scanner.hasNext()) {
				pageContents.append(scanner.nextLine());	
			}
			
			/*
			File spy = new File("src/panda/cardutil/other/bye.txt");
			System.out.println(spy.createNewFile());
			*/
			
		} catch (Exception e) {
			e.printStackTrace();
		}		
		
		/* <td class = \"TCGPHiLoLow\">([.]*)</a> */
		
		Pattern pattern = Pattern.compile("[abc]at", Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher("bat cat rat");
		
		pattern = Pattern.compile("<td class = \"TCGPHiLoLow\">(.*)</a>");
		matcher = pattern.matcher(pageContents);
		
		while(matcher.find()) {
			System.out.println(matcher.group());
		}
	}
	
	public static int fibonacci(int n) {
		if(n==0 || n==1) {
			return 1;
		}
		
		int[] terms = new int[n];
		terms[0] = 1;
		terms[1] = 1;
		
		for(int i = 2; i < n; i++) {
			terms[i] = terms[i-1] + terms[i-2];
		}
		
		return terms[n-1];
	}
}